package com.wish.g3.account.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.common.core.utils.StringUtils;
import com.wish.common.core.utils.poi.ExcelUtil;
import com.wish.common.core.web.controller.BaseController;
import com.wish.common.core.web.domain.AjaxResult;
import com.wish.common.core.web.page.TableDataInfo;
import com.wish.common.log.annotation.Log;
import com.wish.common.log.enums.BusinessType;
import com.wish.common.security.annotation.RequiresPermissions;
import com.wish.g3.account.entity.CwBalance;
import com.wish.g3.account.service.ICwBalanceService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 企业账户流水明细(企业账户变动历史记录) 前端控制器
 * </p>
 *
 * @author wish
 * @since 2022-11-23
 */
@RestController
@RequestMapping("/balance")
public class CwBalanceController extends BaseController {
    @Autowired
    private ICwBalanceService tbCwBalanceService;

    /**
     * 查询企业账户流水明细(企业账户变动历史记录)列表
     */
    @RequiresPermissions("account:balance:list")
    @GetMapping("/list")
    public TableDataInfo list(CwBalance tbCwBalance)
    {
        startPage();
        QueryWrapper wapper = new QueryWrapper();
        if (tbCwBalance.getBusinessId() != null){
            wapper.eq("business_id",tbCwBalance.getBusinessId());
        }

        if (StringUtils.hasText(tbCwBalance.getBusinessName())){
            wapper.eq("business_name",tbCwBalance.getBusinessName());
        }
        List<CwBalance> list = tbCwBalanceService.list(wapper);
        return getDataTable(list);
    }

    /**
     * 导出企业账户流水明细(企业账户变动历史记录)列表
     */
    @RequiresPermissions("account:balance:export")
    @Log(title = "企业账户流水明细(企业账户变动历史记录)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwBalance tbCwBalance)
    {
        List<CwBalance> list = tbCwBalanceService.list();
        ExcelUtil<CwBalance> util = new ExcelUtil<CwBalance>(CwBalance.class);
        util.exportExcel(response, list, "企业账户流水明细(企业账户变动历史记录)数据");
    }

    /**
     * 获取企业账户流水明细(企业账户变动历史记录)详细信息
     */
    @RequiresPermissions("account:balance:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCwBalanceService.getById(id));
    }

    /**
     * 新增企业账户流水明细(企业账户变动历史记录)
     */
    @RequiresPermissions("account:balance:add")
    @Log(title = "企业账户流水明细(企业账户变动历史记录)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwBalance tbCwBalance)
    {
        return toAjax(tbCwBalanceService.save(tbCwBalance));
    }

    /**
     * 修改企业账户流水明细(企业账户变动历史记录)
     */
    @RequiresPermissions("account:balance:edit")
    @Log(title = "企业账户流水明细(企业账户变动历史记录)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwBalance tbCwBalance)
    {
        return toAjax(tbCwBalanceService.saveOrUpdate(tbCwBalance));
    }

    /**
     * 删除企业账户流水明细(企业账户变动历史记录)
     */
    @RequiresPermissions("account:balance:remove")
    @Log(title = "企业账户流水明细(企业账户变动历史记录)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCwBalanceService.removeByIds(Arrays.asList(ids)));
    }

}
